package com.tdam_2012_g7.notification;

import com.tdam_2012_g7.Main_Activity;
import com.tdam_2012_g7.R;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;

public class NotificationController {

	private static final int MESSAGE = 1;
	private static String contentText;
	private static String contentTitle;

	//Notifica si el mensaje WEB se envio correctamente
	public static void notifyMessageSending(Context context, boolean resultSuccess) {

		String tickerText = context.getString(R.string.tickerText_mensaje);

		Notification notification = new Notification(R.drawable.icon_android,
				tickerText, System.currentTimeMillis());

		PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
				getOpenApplicationIntent(context), 0);

		
		contentTitle =  context.getString(R.string.content_title_mensaje);
		
		if (resultSuccess){
			contentText = context.getString(R.string.content_text_success);
		}else{
			contentText = context.getString(R.string.content_text_fail);
		}
		notification.setLatestEventInfo(context, contentTitle, contentText,
				pendingIntent);
		String ns = Context.NOTIFICATION_SERVICE;
		
		notification.flags |= Notification.FLAG_AUTO_CANCEL;
		
		NotificationManager mNotifactionManager = (NotificationManager) context.getSystemService(ns);

		mNotifactionManager.notify(MESSAGE, notification);
	}
	
	public static Intent getOpenApplicationIntent(Context context) {
		Intent intent = new Intent();
		intent.setAction(Intent.ACTION_MAIN);
		intent.addCategory(Intent.CATEGORY_LAUNCHER);
		intent.setComponent(new ComponentName(context.getPackageName(),
				Main_Activity.class.getName()));
		return intent;

	}
}
